<template>
  <div class="loop-node-card" ref="card">
    <!-- 删除蓝点锚点相关代码 -->
    <div class="header">
      <span class="icon"></span>
      <span class="title">循环节点</span>
    </div>
    <div class="desc">循环执行指定逻辑</div>
    <div class="section-title">循环配置</div>
    <div class="config-list">
      <div class="config-row">
        <label>循环类型：</label>
        <el-select v-model="localConfig.loopType" size="small" style="width: 100%;" @change="emitChange">
          <el-option label="固定次数" value="fixed" />
          <el-option label="条件循环" value="condition" />
          <el-option label="列表循环" value="list" />
        </el-select>
      </div>
      <div class="config-row" v-if="localConfig.loopType === 'fixed'">
        <label>循环次数：</label>
        <el-input-number v-model="localConfig.loopCount" :min="1" :max="1000" size="small" style="width: 100%;" @change="emitChange" />
      </div>
      <div class="config-row" v-if="localConfig.loopType === 'condition'">
        <label>循环条件：</label>
        <el-input v-model="localConfig.condition" type="textarea" size="small" placeholder="请输入循环条件表达式" @change="emitChange" />
      </div>
      <div class="config-row" v-if="localConfig.loopType === 'list'">
        <label>循环列表：</label>
        <el-input v-model="localConfig.listVariable" size="small" placeholder="请输入列表变量名" @change="emitChange" />
      </div>
      <div class="config-row">
        <label>最大循环次数：</label>
        <el-input-number v-model="localConfig.maxLoopCount" :min="1" :max="10000" size="small" style="width: 100%;" @change="emitChange" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LoopNodeCard',
  props: {
    config: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      localConfig: { ...this.config }
    }
  },
  watch: {
    config: {
      handler(newVal) {
        this.localConfig = { ...newVal }
      },
      deep: true
    }
  },
  methods: {
    emitChange() {
      this.$emit('change', { ...this.localConfig })
    }
  }
};
</script>

<style scoped>
.loop-node-card {
  width: 300px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 2px 8px 0 rgba(0,0,0,0.04);
  padding: 16px;
  position: relative;
}

.node-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2979ff;
  border: 2px solid #fff;
  box-shadow: 0 0 2px #2979ff;
  cursor: pointer;
  z-index: 10;
  transition: box-shadow 0.2s;
}

.node-dot--left-top {
  top: -6px;
  left: -6px;
}

.node-dot--right-top {
  top: -6px;
  right: -6px;
}

.node-dot:hover {
  box-shadow: 0 0 8px #2979ff;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  position: relative;
}

.icon {
  width: 32px;
  height: 32px;
  background: #fff3e0;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  position: relative;
}

.icon::after {
  content: '⟲';
  display: block;
  width: 16px;
  height: 16px;
  color: #ff9800;
  font-size: 16px;
  font-weight: bold;
  position: absolute;
  left: 8px;
  top: 8px;
}

.title {
  font-size: 18px;
  font-weight: bold;
}

.desc {
  color: #888;
  font-size: 13px;
  margin-bottom: 8px;
}

.section-title {
  font-weight: bold;
  margin-bottom: 8px;
}

.config-list {
  background: #fafbfc;
  border-radius: 6px;
  padding: 12px;
}

.config-row {
  margin-bottom: 12px;
}

.config-row:last-child {
  margin-bottom: 0;
}

.config-row label {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  color: #333;
}
</style> 